<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.CreateCarreservationTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:link value="#{bundle.CreateCarShowAllLink}" outcome="/car/List"/>
            <h:panelGroup id="messagePanel" layout="block">
                <p:messages />
            </h:panelGroup>
            <h:form>
                <h:panelGrid columns="2">
                    <h:outputLabel value="#{bundle.CreateCarreservationLabel_car}" for="car" />
                    <h:selectOneMenu id="car" value="#{carreservationController.selected.car}" 
                                     title="#{bundle.CreateCarreservationTitle_car}" 
                                     required="true" 
                                     requiredMessage="#{bundle.CreateCarreservationRequiredMessage_car}">
                        <f:selectItems value="#{carController.itemsAvailableSelectOne}"/>
                        <f:ajax event="change" render="deposit totalsum" listener="#{carreservationController.updateTotalSum()}"/>
                    </h:selectOneMenu>
                    <h:outputLabel value="#{bundle.CreateCarreservationLabel_place}" />
                    <h:selectOneMenu value="#{carreservationController.selected.pickUpLocation}" 
                                     title="#{bundle.CreateCarreservationTitle_car}" 
                                     required="true" 
                                     requiredMessage="You must select a place">
                        <f:selectItems value="#{pickuplocationController.itemsAvailableSelectOne}"/>
                    </h:selectOneMenu>                    
                    
                    #{bundle.pickUpDate} 
                    <p:calendar value="#{carreservationController.selected.pickUpDate}" 
                                pattern="dd/MM/yyyy" showOn="button" 
                                required="true"
                                requiredMessage="Please enter a start date">
                        <f:validator validatorId="dateRangeValidator" />
                        <f:attribute name="confirm" value="#{confirm}" />
                        <p:ajax event="dateSelect" update="deposit totalsum" listener="#{carreservationController.handleDateSelectPickUpDate}"/>
                    </p:calendar>
                    Drop of date: 
                    <p:calendar value="#{carreservationController.selected.dropOffDate}" onselect="update"
                                pattern="dd/MM/yyyy" showOn="both"
                                requiredMessage="Please enter a drop of date" 
                                binding="#{confirm}" rendered="true">
                        <p:ajax event="dateSelect" update="@form" listener="#{carreservationController.handleDateSelectDropOfDate}"/>
                    </p:calendar>
                    <h:outputText value="#{bundle.CreateCarreservationLabel_deposit}" />
                    <h:outputText id="deposit" value="#{carreservationController.selected.deposit &lt; 0 ? 0 : carreservationController.selected.deposit}$" 
                                  title="#{bundle.CreateCarreservationTitle_deposit}" />
                    <h:outputText value="#{bundle.TotalSum}:" />
                    <h:outputText id="totalsum" value="#{carreservationController.selected.totalSum &lt; 0 ? 0 : carreservationController.selected.totalSum}$" 
                                  title="#{bundle.TotalSum}:" />
                </h:panelGrid>
                <br />
                <h:commandLink action="#{carreservationController.create}" value="#{bundle.CreateCarreservationSaveLink}" />
            </h:form>
            <br />
        </ui:define>
    </ui:composition>
</html>